/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package DAL;

import DataCar.Car;
import java.util.List;

/**
 *
 * @author Pasha
 */
public class CarManeger {
    public void Race(List<Car> cars)
    {
        for(Car c: cars)
        {
            try
            {
                c.Print();
                c.ChangeCar(c);
                c.Print();
                CheackCar(c);
            }
            catch(NotFuelException nf)
            {
                System.out.println(nf.toString());
            }
            catch(PunchedWheelException pw)
            {
                System.out.println(pw.toString());
            }
            catch(NoPedalException np)
            {
                System.out.println(np.toString());
            }
            catch(NoDriverException nd)
            {
                System.out.println(nd.toString());
            }
        }
        
        Winners(cars);
    }
    
    protected void Winners(List<Car> cars)
    {
        for(Car c: cars)
        {
            if(c.noDriver != true && c.noPedal != true && c.notFuel != true && c.punchedWheel != true)
            {
                System.out.println(String.format(c.name + " is winner!!!\n"));
            }
            else
            {
                System.out.println(String.format(c.name + " is not winner!!!\n"));
            }
        }
    }
    
    protected void CheackCar(Car car) throws NotFuelException, PunchedWheelException, NoPedalException, NoDriverException
    {
        if(car.noDriver == true)
        {
            throw new NotFuelException(car.name);
        }
        
        if(car.noPedal == true)
        {
            throw new PunchedWheelException(car.name);
        }
        
        if(car.notFuel == true)
        {
            throw new NoPedalException(car.name);
        }
        
        if(car.punchedWheel == true)
        {
            throw new NoDriverException(car.name);
        }
    }
    
}
